<style scoped>
    .update-spare-page .condition{line-height: 36px;display:inline-block;}
    .update-spare-page .cancel a{color:#fff;}

    .update-spare-page .el-form-item.selectMB10{margin-bottom:10px;}

    /* 新增的弹窗 */
    .update-spare-page .el-dialog.el-dialog--small{width:60%;min-height:300px;}
    .update-spare-page .el-dialog .el-dialog__body{padding-bottom:0;}
    .update-spare-page .el-dialog .el-form-item__content{}
    .update-spare-page .el-dialog .el-input{width:100%;}
    .update-spare-page .el-dialog .el-form .el-form-item{}
    .update-spare-page .el-dialog .el-dialog__body .el-form-item:last-of-type{margin-bottom:0;}
    .update-spare-page .el-dialog .el-form-item__label{text-align: left;}


    .update-spare-page .el-dialog .title{display:inline-block;}
    .update-spare-page ._box{position:relative;padding-left:5px;display:inline-block;width:331px;height:30px;line-height:30px;text-align:left;border:1px solid #cccccc;margin-bottom:30px;}
    .update-spare-page ._box p{font-size:12px;color:#666666;}
    .update-spare-page ._box .browse_btn{position:absolute;right:0;top:0;width:80px;height:30px;line-height:30px;text-align:center;background: #f5f5f5;border-left:1px solid #cccccc;font-size:14px;color:#666666;}
    .update-spare-page ._box .browse_btn input{position:absolute;right:0;top:0;width:100%;height:100%;cursor:pointer;cursor:hand;opacity: 0;}

    /* 菜单导航 */
    .update-spare-page .el-menu{margin-bottom:15px;}
    .update-spare-page .el-menu .el-menu-item{height:36px;line-height:36px;}
    .update-spare-page .under-table{display:none;}
    .update-spare-page .supplier{display:block;}
    /*点击新增按钮   弹框*/
    .update-spare-page #supplierMark .el-dialog.el-dialog--small .el-dialog__footer{height:60px;position:relative;min-height:440px;}
    .update-spare-page #supplierMark .el-pagination{text-align:left;}
    .update-spare-page #supplierMark .el-pagination .el-select{width:120px;}


</style>

<template>
    <div class="update-spare-page">
        <el-form :inline="true" :model="spareMessage" class="demo-form-inline" style="margin-bottom:20px;border-bottom:1px solid #ccc;"  ref="spareMessage">
            <!--备件编码-->
            <el-form-item :label="nowLangue.spareCode" prop="code" class="selectMB10">
                <el-input size="mini" disabled v-model="spareMessage.code"></el-input>
            </el-form-item>
            <!--备件名称-->
            <el-form-item :label="nowLangue.spareName" prop="name" class="selectMB10">
                <el-input size="mini" disabled v-model="spareMessage.name" :title="spareMessage.name"></el-input>
            </el-form-item>
            <!--备件小类-->
            <el-form-item  :label="nowLangue.spareSubClass" class="selectMB10">
                <el-select size="mini"  v-model="spareMessage.subclass" :placeholder="nowLangue.pleaseSelect">
                    <el-option v-for="(subclass,index) in subclassLists" :key="index" :label="subclass.name" :value="subclass.code"></el-option>
                </el-select>
            </el-form-item>
            <!--计划备件大类-->
            <el-form-item :label="nowLangue.planCategory" prop="planCategory" class="selectMB10">
                <el-select size="mini"  v-model="spareMessage.planCategory" :placeholder="nowLangue.pleaseSelect">
                    <el-option v-for="(planCategory,index) in planCategoryLists" :key="index" :label="planCategory.name" :value="planCategory.code"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="" class="selectMB10 checkboxAlign">
                <!--启用-->
                <el-checkbox v-model="spareMessage.enabled"  @change="serializabledefalut" v-cloak>{{nowLangue.enable}}</el-checkbox>
                <!--服务卡-->
                <el-checkbox v-model="spareMessage.serviceCard" v-cloak>{{nowLangue.serviceCard}}</el-checkbox>
            </el-form-item>
            <!--备件属性-->
             <el-form-item :label="nowLangue.spareAttr" prop="property" class="selectMB10">
                <el-select size="mini" clearable  v-model="spareMessage.property" :placeholder="nowLangue.pleaseSelect">
                    <el-option v-for="(property,index) in spareMessageDropDown['meterial.property']" :key="index" :label="property.label" :value="property.value"></el-option>
                </el-select>
            </el-form-item>
            <!--序列化-->
            <el-form-item :label="nowLangue.serialize" prop="serializable" :rules="[{ required: true, message: nowLangue.required}]" class="selectMB10">
                <el-select size="mini"  v-model="spareMessage.serializable" :placeholder="nowLangue.pleaseSelect">
                    <el-option v-for="(serializable,index) in spareMessageDropDown['meterial.serializable']" :key="index" :label="serializable.label" :value="serializable.value"></el-option>
                </el-select>
            </el-form-item>
            <!--是否可借用-->
            <el-form-item :label="nowLangue.isBorrowable" prop="borrowable" :rules="[{ required: true, message: nowLangue.required}]" class="selectMB10">
                <el-select size="mini"  v-model="spareMessage.borrowable" :placeholder="nowLangue.pleaseSelect">
                    <el-option v-for="(borrowable,index) in spareMessageDropDown['meterial.borrowable']" :key="index" :label="borrowable.label" :value="borrowable.value"></el-option>
                </el-select>
            </el-form-item>
            <!--Lenovo是否可销售-->
            <el-form-item :label="nowLangue.lenovoSellable" prop="lenovoSellable" :rules="[{ required: true, message: nowLangue.required}]" class="selectMB10">
                <el-select size="mini"  v-model="spareMessage.lenovoSellable" :placeholder="nowLangue.pleaseSelect">
                    <el-option v-for="(lenovoSellable,index) in spareMessageDropDown['meterial.lenovoSellable']" :key="index" :label="lenovoSellable.label" :value="lenovoSellable.value"></el-option>
                </el-select>
            </el-form-item>
            <!--Think是否可销售-->
            <el-form-item :label="nowLangue.thinkSellable" prop="thinkSellable" :rules="[{ required: true, message: nowLangue.required}]" class="selectMB10">
                <el-select size="mini"  v-model="spareMessage.thinkSellable" :placeholder="nowLangue.pleaseSelect">
                    <el-option v-for="(thinkSellable,index) in spareMessageDropDown['meterial.thinkSellable']" :key="index" :label="thinkSellable.label" :value="thinkSellable.value"></el-option>
                </el-select>
            </el-form-item>
            <!--是否自动分配-->
            <el-form-item :label="nowLangue.canAutoAllot" prop="canAutoAllot" :rules="[{ required: true, message: nowLangue.required}]" class="selectMB10">
                <el-select size="mini"  v-model="spareMessage.canAutoAllot" :placeholder="nowLangue.pleaseSelect">
                    <el-option v-for="(canAutoAllot,index) in spareMessageDropDown['meterial.canAutoAllot']" :key="index" :label="canAutoAllot.label" :value="canAutoAllot.value"></el-option>
                </el-select>
            </el-form-item>
            <!--停产支持MOQ-->
            <el-form-item :label="nowLangue.supportMOQ" prop="supportMOQ" :rules="[{ required: true, message: nowLangue.required},{ type: 'number', message: '停产支持MOQ必须为数字值'}]" class="selectMB10">
                <el-input size="mini"  v-model.number="spareMessage.supportMOQ" :placeholder="nowLangue.pleaseImport+nowLangue.supportMOQ"></el-input>
            </el-form-item>
            <!--引入时间-->
             <el-form-item :label="nowLangue.leadInTime" prop="introduceTime" class="selectMB10">
                <el-date-picker type="date" size="mini" :editable="false" readonly v-model="spareMessage.introduceTime":placeholder="nowLangue.pleaseSelect+nowLangue.leadInTime"></el-date-picker>
            </el-form-item>
            <!--状态-->
            <el-form-item :label="nowLangue.status" prop="status" class="selectMB10">
                <el-select size="mini" clearable  v-model="spareMessage.status" :placeholder="nowLangue.pleaseSelect">
                    <el-option v-for="(status,index) in spareMessageDropDown['meterial.status']" :key="index" :label="status.label" :value="status.value"></el-option>
                </el-select>
            </el-form-item>
            <!--特殊运输要求-->
            <el-form-item :label="nowLangue.specialTransportRequirements" prop="specialTransportRequired" :rules="[{ required: true, message: nowLangue.required}]" class="selectMB10">
                <el-select size="mini" v-model="spareMessage.specialTransportRequired" :placeholder="nowLangue.pleaseSelect">
                    <el-option v-for="(specialTransportRequired,index) in spareMessageDropDown['meterial.specialTransportRequired']" :key="index" :label="specialTransportRequired.label" :value="specialTransportRequired.value"></el-option>
                </el-select>
            </el-form-item>
            <!--采购优先级-->
            <el-form-item :label="nowLangue.procurementPriority" class="selectMB10" prop="purchasePriority" :rules="[{ required: true, message: nowLangue.required}]" >
                <el-select size="mini" v-model="spareMessage.purchasePriority" :placeholder="nowLangue.pleaseSelect">
                    <el-option v-for="(purchasePriority,index) in spareMessageDropDown['meterial.purchasePriority']" :key="index" :label="purchasePriority.label" :value="purchasePriority.value"></el-option>
                </el-select>
            </el-form-item>
            <!--是否可供货-->
            <el-form-item :label="nowLangue.canSupply" prop="canSupply" :rules="[{ required: true, message: nowLangue.required}]" class="selectMB10">
                <el-select size="mini" v-model="spareMessage.canSupply" :placeholder="nowLangue.pleaseSelect">
                    <el-option v-for="(canSupply,index) in spareMessageDropDown['meterial.canSupply']" :key="index" :label="canSupply.label" :value="canSupply.value"></el-option>
                </el-select>
            </el-form-item>
            <!--不可供货原因-->
            <el-form-item :label="nowLangue.noSupplyReason" v-if="spareMessage.canSupply==0"  prop="noSupplyReason" class="selectMB10" :rules="[{ max: 200, message: nowLangue.lessThan200}]">
                <el-input size="mini" v-model.trim="spareMessage.noSupplyReason" :placeholder="nowLangue.pleaseImport+nowLangue.noSupplyReason"></el-input>
            </el-form-item>
            <!--采购方式-->
            <el-form-item :label="nowLangue.purchaseMethod" prop="purchaseMethod" :rules="[{ required: true, message: nowLangue.required}]" class="selectMB10">
                <el-select size="mini" v-model="spareMessage.purchaseMethod" @change="selectPurchaseMethod" :placeholder="nowLangue.pleaseSelect">
                    <el-option v-for="(purchaseMethod,index) in spareMessageDropDown['meterial.purchaseMethod']" :key="index" :label="purchaseMethod.label" :value="purchaseMethod.value"></el-option>
                </el-select>
            </el-form-item>
            <!-- 服务工厂 -->
            <el-form-item :label="nowLangue.serviceFactory" prop="serviceFactory" class="selectMB10">
                <el-select size="mini" clearable  v-model="spareMessage.serviceFactory" :placeholder="nowLangue.pleaseSelect">
                    <!--
                    <el-option v-for="serviceFactory in spareMessage.serviceFactoryList" :label="serviceFactory.label" :value="serviceFactory.value"></el-option>
                    -->
                    <el-option label="是" value="true"></el-option>
                    <el-option label="否" value="false"></el-option>
                </el-select>
            </el-form-item>
        </el-form>
         <el-form :inline="true" :model="spareMessage" class="demo-form-inline" style="margin-bottom:20px;border-bottom:1px solid #ccc;">
             <!--供应商备件号-->
            <el-form-item :label="nowLangue.providerNo" class="selectMB10">
                <el-input size="mini" v-model="spareMessage.providerNo" :placeholder="nowLangue.pleaseImport+nowLangue.providerNo"></el-input>
            </el-form-item>
             <!--原厂备件号-->
            <el-form-item :label="nowLangue.originalSpareNumber" class="selectMB10">
                <el-input size="mini" v-model="spareMessage.originalNo" :placeholder="nowLangue.pleaseImport+nowLangue.originalSpareNumber"></el-input>
            </el-form-item>
             <!--原厂商-->
            <el-form-item :label="nowLangue.originalManufacturer" class="selectMB10">
                <el-select size="mini" clearable  v-model="originalManufacturerName" @change="bianhua" filterable :placeholder="nowLangue.pleaseSelect">
                    <el-option v-for="originalManufacturerName in originalManufacturerNameList"  :key="originalManufacturerName.partnerName" :label="originalManufacturerName.partnerName" :value="originalManufacturerName.partnerName">
                        <span style="float: left">{{ originalManufacturerName.partnerName }}</span>
                        <span style="float: right; color: #8492a6; font-size: 13px">{{ originalManufacturerName.partnerCode }}</span>
                    </el-option>
                </el-select>
            </el-form-item>
             <!--原产地-->
            <el-form-item :label="nowLangue.countryOfOrigin" class="selectMB10">
                 <el-select size="mini" clearable  v-model="spareMessage.originalProduceArea" :placeholder="nowLangue.pleaseSelect" >
                    <el-option v-for="(originalProduceArea,index) in spareMessageDropDown['meterial.originalProduceArea']" :key="index" :label="originalProduceArea.label" :value="originalProduceArea.value"></el-option>
                </el-select>
            </el-form-item>
             <!--净重(单位：克)-->
            <el-form-item :label="nowLangue.suttle" class="selectMB10">
                <el-input size="mini" v-model="spareMessage.suttle" :placeholder="nowLangue.pleaseImport+nowLangue.suttle"></el-input>
            </el-form-item>
             <!--原材料-->
            <el-form-item :label="nowLangue.rawMaterial" class="selectMB10">
                <el-input size="mini" v-model="spareMessage.rawMaterials" :placeholder="nowLangue.pleaseImport+nowLangue.rawMaterial"></el-input>
            </el-form-item>
             <!--规格-->
            <el-form-item :label="nowLangue.standard" class="selectMB10">
                <el-input size="mini" v-model="spareMessage.standard" :placeholder="nowLangue.pleaseImport+nowLangue.standard"></el-input>
            </el-form-item>
             <!--量产MOQ-->
            <el-form-item :label="nowLangue.outPutMOQ" class="selectMB10" prop="volumeProductionMOQ" :rules="[{ type: 'number', message: '量产MOQ必须为数字值'}]">
                <el-input size="mini" v-model.number="spareMessage.volumeProductionMOQ" :placeholder="nowLangue.pleaseImport+nowLangue.outPutMOQ"></el-input>
            </el-form-item>
             <!--最小包装单位-->
            <el-form-item :label="nowLangue.minimumPackingUnit" class="selectMB10">
                <el-input size="mini" v-model="spareMessage.minimumPackageUnit" :placeholder="nowLangue.pleaseImport+nowLangue.minimumPackingUnit"></el-input>
            </el-form-item>
             <!--PSI标志-->
            <el-form-item :label="nowLangue.PSISign" prop="psiFlag" class="selectMB10">
                <el-select size="mini" clearable  v-model="spareMessage.psiFlag" :placeholder="nowLangue.pleaseSelect">
                    <el-option v-for="(psiFlag,index) in spareMessageDropDown['meterial.psiFlag']" :key="index" :label="psiFlag.label" :value="psiFlag.value"></el-option>
                </el-select>
            </el-form-item>
             <!--ROHS属性-->
            <el-form-item :label="nowLangue.ROHSAttr" prop="rohsProperty" class="selectMB10">
                <el-select size="mini" clearable  v-model="spareMessage.rohsProperty" :placeholder="nowLangue.pleaseSelect">
                    <el-option v-for="(rohsProperty,index) in spareMessageDropDown['meterial.rohsProperty']" :key="index" :label="rohsProperty.label" :value="rohsProperty.value"></el-option>
                </el-select>
            </el-form-item>
             <!--备件单位-->
            <el-form-item :label="nowLangue.spareUnit" prop="unit" :rules="[{ required: true, message: nowLangue.required}]" class="selectMB10">
                <el-select size="mini" v-model="spareMessage.unit" :placeholder="nowLangue.pleaseSelect">
                    <el-option v-for="(unit,index) in spareMessageDropDown['meterial.unit']" :key="index" :label="unit.label" :value="unit.value"></el-option>
                </el-select>
            </el-form-item>
             <!--EOL日期-->
            <el-form-item :label="nowLangue.EOLDate" class="selectMB10">
                <el-date-picker type="date" size="mini" :editable="false" v-model="spareMessage.eOLTime"  :placeholder="nowLangue.pleaseSelect+nowLangue.EOLDate"></el-date-picker>
            </el-form-item>
             <!--备注信息-->
            <el-form-item :label="nowLangue.memoMes" class="selectMB10">
                <el-input size="mini" v-model="spareMessage.remark" :placeholder="nowLangue.pleaseImport+nowLangue.memoMes"></el-input>
            </el-form-item>
            <!--保存-->
            <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="saveMSG" v-text="nowLangue.save" :disabled="saveDisabled"></el-button>
             <!--取消-->
            <el-button size="mini" type="danger" class="cancel bolder outsideBtnBS" @click="cancleUpdate" v-text="nowLangue.cancel">
            </el-button>
        </el-form>
        <!-- 菜单导航 -->
        <el-menu default-active="supplier" class="el-menu-demo" mode="horizontal" @select="handleSelect">
            <!--供应商-->
            <el-menu-item index="supplier" v-text="nowLangue.supplier"></el-menu-item>
            <!--索赔商-->
            <el-menu-item index="claimMaker" v-text="nowLangue.claimMaker"></el-menu-item>
            <!--维修商-->
            <el-menu-item index="maintainer" v-text="nowLangue.maintainer"></el-menu-item>
        </el-menu>
        <!--表格-->
        <!--新增-->
        <el-button class="bolder outsideBtnBS" size="mini" type="danger"  @click="newSupplier(supplierType)" v-text="nowLangue.create"></el-button>
        <!--保存-->
        <el-button class="bolder outsideBtnBS" size="mini" type="danger"  @click="saveSupplier(supplierType)" v-text="nowLangue.save"></el-button>
        <!-- 供应商 -->
        <el-table class="under-table supplier" :data="supplierData" border style="margin-top:16px;width: 100%;" v-loading.body="loading" element-loading-text="拼命加载中">
            <!--序-->
            <el-table-column type="index" header-align="center" align="center" :label="nowLangue.sequence"  width="40"></el-table-column>
            <!--操作-->
            <el-table-column :label="nowLangue.operate" header-align="center" align="center" width="60">
                <template scope="scope">
                    <!--启用-->
                    <button class="operationItem bolder" v-if="!scope.row.status" @click="handleStatus(scope.$index, scope.row)" v-text="nowLangue.enable"></button>
                    <!--禁用-->
                    <button class="operationItem bolder" v-else @click="handleStatus(scope.$index, scope.row)" v-text="nowLangue.forbidden"></button>
                </template>
            </el-table-column>
            <!--供应商编号-->
            <el-table-column prop="code" :label="nowLangue.supplierNo" header-align="center" width="120" show-overflow-tooltip></el-table-column>
            <!--供应商名称-->
            <el-table-column prop="name" :label="nowLangue.supplierName" header-align="center" :width="myPurchaseWidth" show-overflow-tooltip></el-table-column>
            <!--默认-->
            <el-table-column  :label="nowLangue.default" header-align="center" align="center" width="80" v-if="myPurchaseMethod==1">
                <template scope="scope">
                    <el-radio v-model="defaultSupplier" :label="scope.row.id" size="mini">&nbsp;</el-radio>
                </template>
            </el-table-column>
            <!--供货比例-->
            <el-table-column prop="matchStatus" :label="nowLangue.supplyProportion" header-align="center" align="center" width="80" v-else>
                <!--单独供货时不显示-->
                <template scope="scope">
                    <el-checkbox v-model="scope.row.matchStatus" v-if="scope.row.status == false" size="mini" @change="selectSpare(scope.$index, scope.row)"></el-checkbox>
                    <el-checkbox v-model="scope.row.matchStatus" v-else disabled size="mini"></el-checkbox>
                </template>
            </el-table-column>
            <!--比例(%)-->
            <el-table-column prop="proportion" :label="nowLangue.percentage" header-align="center" width="100" v-if="myPurchaseMethod==2">
                 <template scope="scope">
                    <el-input size="mini" v-model="scope.row.proportion" v-if="scope.row.status == false" @change="changeProportion(scope.$index, scope.row)"></el-input>
                    <el-input size="mini" v-model="scope.row.proportion" v-else disabled></el-input>
                </template>
            </el-table-column>
            <!--复制到索赔商-->
            <el-table-column  :label="nowLangue.copyToTheClaimMaker" header-align="center" align="center" width="120" show-overflow-tooltip>
                <template scope="scope">
                    <el-button size="mini" type="primary" @click="copeClaimMaker(scope.$index, scope.row)" v-text="nowLangue.copyToTheClaimMaker" :disabled="copyCDisabled"></el-button>
                </template>
            </el-table-column>
            <!--复制到维修商-->
            <el-table-column :label="nowLangue.copyToTheService" header-align="center" align="center" width="120" show-overflow-tooltip>
                 <template scope="scope">
                    <el-button size="mini" type="primary" @click="copeMaintainer(scope.$index, scope.row)" v-text="nowLangue.copyToTheService" :disabled="copyMDisabled"></el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- 索赔商 -->
        <el-table class="under-table claimMaker" :data="supplierData" border style="margin-top:16px;width: 100%;" v-loading.body="loading" element-loading-text="拼命加载中">
            <!--序-->
            <el-table-column type="index" header-align="center" align="center" :label="nowLangue.sequence"  width="40"></el-table-column>
            <!--操作-->
            <el-table-column :label="nowLangue.operate" header-align="center" align="center" width="60">
                <template scope="scope">
                    <!-- 启用-->
                    <button class="operationItem bolder" v-if="!scope.row.status" @click="handleStatus(scope.$index, scope.row)" v-text="nowLangue.enable"></button>
                    <!--禁用 -->
                    <button class="operationItem bolder" v-else @click="handleStatus(scope.$index, scope.row)" v-text="nowLangue.forbidden"></button>
                </template>
            </el-table-column>
            <!--索赔商编号-->
            <el-table-column prop="code" :label="nowLangue.claimNo" header-align="center" width="180" show-overflow-tooltip></el-table-column>
            <!--索赔商名称-->
            <el-table-column prop="name" :label="nowLangue.claimName" header-align="center" show-overflow-tooltip></el-table-column>
            <!--默认-->
            <el-table-column  :label="nowLangue.default" header-align="center" align="center" width="80">
                <template scope="scope">
                    <el-radio v-model="defaultClaimMaker"  :label="scope.row.id" size="mini">&nbsp;</el-radio>
                </template>
            </el-table-column>
        </el-table>
        <!-- 维修商 -->
        <el-table class="under-table maintainer" :data="supplierData" border style="margin-top:16px;width: 100%;" v-loading.body="loading" element-loading-text="拼命加载中">
            <!--序-->
            <el-table-column type="index" header-align="center" align="center" :label="nowLangue.sequence"  width="40"></el-table-column>
            <!--操作-->
            <el-table-column :label="nowLangue.operate" header-align="center" align="center" width="60">
                <template scope="scope">
                    <!--启用-->
                    <button class="operationItem bolder" v-if="!scope.row.status" @click="handleStatus(scope.$index, scope.row)" v-text="nowLangue.enable"></button>
                    <!--禁用-->
                    <button class="operationItem bolder" v-else @click="handleStatus(scope.$index, scope.row)" v-text="nowLangue.forbidden"></button>
                </template>
            </el-table-column>
            <!--维修商编号-->
            <el-table-column prop="code" :label="nowLangue.serviceNo" header-align="center" width="180" show-overflow-tooltip></el-table-column>
            <!--维修商名称-->
            <el-table-column prop="name" :label="nowLangue.serviceName" header-align="center" show-overflow-tooltip></el-table-column>
            <!--默认-->
            <el-table-column  :label="nowLangue.default" header-align="center" align="center" width="80">
                <template scope="scope">
                    <el-radio v-model="defaultMaintainer" :label="scope.row.id" size="mini">&nbsp;</el-radio>
                </template>
            </el-table-column>
        </el-table>

        <!--选择供应商、索赔商、维修商弹框-->
        <!---->
        <el-dialog id="supplierMark" :title="title" :visible.sync="LeadIngInVisible" size="small" :lock-scroll="false">
            <el-form :inline="true" :model="selectForm" class="demo-form-inline">
                <!--供应商编号-->
                <el-form-item :label="nowLangue.supplierNo">
                    <el-input size="mini" v-model="selectForm.code" auto-complete="off" :placeholder="nowLangue.pleaseImport+nowLangue.supplierNo"></el-input>
                    <!--<el-select v-model="originalManufacturerName" filterable :placeholder="nowLangue.pleaseSelect">
                        <el-option v-for="originalManufacturerName in originalManufacturerNameList"  :key="originalManufacturerName.partnerCode" :label="originalManufacturerName.partnerCode" :value="originalManufacturerName.partnerCode">
                            <span style="float: left">{{ originalManufacturerName.partnerName }}</span>
                            <span style="float: right; color: #8492a6; font-size: 13px">{{ originalManufacturerName.partnerCode }}</span>
                        </el-option>
                    </el-select>-->
                </el-form-item>
                <!--供应商名称-->
                <el-form-item :label="nowLangue.supplierName">
                    <el-input size="mini" v-model="selectForm.name" auto-complete="off" :placeholder="nowLangue.pleaseImport+nowLangue.supplierName"></el-input>
                </el-form-item>
                <el-form-item>
                    <!--查询-->
                    <el-button class="bolder outsideBtnBS selectAll" :disabled="selectDisabled" size="mini" type="danger" @click="search(pageIndex,pageSize)" style="    margin-left: 6px!important;" v-text="nowLangue.query"></el-button>
                    <!--确定-->
                    <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="insertMateraialSupplier()" style="    margin-left: 6px!important;" v-text="nowLangue.confirm"></el-button>
                </el-form-item>
            </el-form>
            <!-- 弹框里的表格 -->
            <el-table :data="gridData" border style="width: 100%" @selection-change="handleSelectionChange">
                <!--序-->
                <el-table-column type="index" header-align="center" align="center" :label="nowLangue.sequence"  width="40"></el-table-column>
                <!--<el-table-column property="selectItem" label="选择" header-align="center" align="center" width="100">
                    <template scope="scope">
                        <el-checkbox size="mini" @change="selectMateraialSupplier(scope.$index, scope.row,$event)" :label="scope.row.id">&nbsp;</el-checkbox>
                    </template>
                </el-table-column>-->
                <el-table-column type="selection" width="50" align="center"> </el-table-column>
                <!--供应商编号-->
                <el-table-column property="partnerCode" :label="nowLangue.supplierNo" header-align="center" width="200" show-overflow-tooltip></el-table-column>
                <!--供应商名称-->
                <el-table-column property="partnerName" :label="nowLangue.supplierName" header-align="center" show-overflow-tooltip></el-table-column>
            </el-table>
            <div slot="footer" class="dialog-footer">
                 <!--分页 v-if="isPaging"-->
                <el-pagination  @size-change="handleSizeChange" @current-change="handleCurrentChange"
                                :current-page.sync="currentPage3" :current-page="pageIndex"
                                :page-sizes="[1, 2, 3 , 4, 5]" :page-size="pageSize"
                                layout="total, sizes, prev, pager, next, jumper"
                                :page-count="totalPage" :total="totalNumber">
                </el-pagination>
            </div>

        </el-dialog>

    </div>
</template>

<script>
       export default {
        data() {
            return {
                nowLangue:{},
                materialCode:"",      //要修改或者查看的id  (从上页传过来的)
                spareMessage:{},  //备件基本信息
                subclassLists:[],  //备件小类下拉列表
                planCategoryLists:[],  //计划备件大类
                purchaseMethod: '',  //采购方式
                originalManufacturerNameList:[],   //自动完成原厂商
                spareMessageDropDown:{},   // 备件信息中的下拉列表中的值
                originalManufacturerName:"",     //原厂商
                originalManufacturerid:"",
                loading:false,
                //  供应商、索赔商、维修商
                supplierData: [],
                myPurchaseMethod:"",
                supplierId:1,    //供应商id
                LeadIngInVisible: false,     //新增供应商、索赔商、维修商
                supplierType:1,    //供应商1  索赔商2   维修商3
                defaultSupplier:'',    //供应商里应该有一个默认供应商
                defaultClaimMaker:'',    //供应商里应该有一个默认索赔商
                defaultMaintainer:'',    //供应商里应该有一个默认维修商
                selectForm:{
                    name:'',
                    code:''
                },
                title:"",   //选择供应商、索赔商、维修商
                // 弹框查询出来的供应商列表
                gridData: [],
                //isPaging:false,    //是否显示分页
                pageIndex:1,    //当前页（必传）
                pageSize :5,   //每页多少条
                currentPage3:3,    //当前显示3页
                totalNumber: 20,     //总条数
                totalPage:2,    //总页数

                supplyList:[],   //选择多个供应商，采用供货比例的采购方式
                providerList:[],      //新增供应商弹框中，选中的供应商的信息


                partnerIds:[], // 供应商、索赔商、维修商列表中已存在的数据的id
                selectedSupplyScale:[],//选中的供货比例
                myPurchaseWidth:"",//供应商名称宽度
                
                selectDisabled:false,   //查询禁用
                saveDisabled:false,      // 保存操作按钮禁用
                saveSDisabled:false,     // 保存供应商的修改操作按钮禁用
                copyCDisabled:false,     //复制到索赔商操作按钮禁用
                copyMDisabled:false      //复制到维修商操作按钮禁用
            };
        },
        created:function(){
            var _this=this;
            _this.languageType=="zh"?_this.nowLangue=_this.language.zh:_this.nowLangue=_this.language.en;
        },
        computed:{
            languageType(){
                return this.$store.state.languageType;
            }
        },
        watch:{
            languageType(){
                var _this=this;
                _this.languageType=="zh"?_this.nowLangue=_this.language.zh:_this.nowLangue=_this.language.en;
            }
        },
        mounted:function(){
            var _this=this;
            _this.$store.commit('currentActive', 'UpdateSpare');
            _this.materialCode=_this.$route.query.materialCode;        //?
            _this.loading=true;

            $.ajax({               //修改  一打开页面调取的接口
                type: 'GET',
                url: _this.metadata_service+"material/findMaterialByCode?materialCode="+_this.materialCode,
                cache: false,
                success: function (data) {
                    if (data.success) {
                        // console.log(data);
                        _this.spareMessage=data.data;
                        _this.originalManufacturerName = data.data.originalManufacturerName;
                        _this.spareMessage.supportMOQ=Number(data.data.supportMOQ);      //停产支持MOQ转化成数字
                        _this.spareMessage.volumeProductionMOQ=Number(data.data.volumeProductionMOQ);  //量产MOQ转化成数字
                        _this.myPurchaseMethod=data.data.purchaseMethod;
                        //console.log("unit="+ _this.spareMessage.unit);
                        _this.prepareData(_this.spareMessage,["property","serializable","borrowable","lenovoSellable","thinkSellable","canAutoAllot","status","specialTransportRequired","purchasePriority","canSupply","purchaseMethod","psiFlag","rohsProperty"]);
                        // console.log("_this.spareMessagexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
                        // console.log(_this.spareMessage);
                        if(_this.spareMessage.purchaseMethod==2){
                            //供货比例
                            _this.myPurchaseWidth=290;
                        }else if(_this.spareMessage.purchaseMethod==1){
                            //单独供货
                            _this.myPurchaseWidth=470;
                        }
                        //供应商列表
                        _this.showSupplierList(_this.spareMessage);
                        _this.loading=false;

                    }else
                        // console.log(data.errorMessage);
                        _this.common.errorTip(data.errorMessage);

                }
            });
            _this.originalManufacturerValue();  //原厂商下拉列表的值  自动完成
            _this.dropDownValue();    //备件信息下拉列表的值

            _this.subclassDownValue();    // 备件小类下拉列表
            _this.planCategoryDownValue();   //计划备件大类下拉列表

            // 选择供应商的弹窗 标题中英文
            if(_this.languageType=="zh"){
                _this.title="选择供应商";
            }else{
                _this.title="selectSupplier";
            }


        },
        methods: {
            // 备件小类下拉列表
            subclassDownValue(){
                var _this=this;
                $.ajax({
                    type: 'GET',
                    url: _this.metadata_service+"subClass/findSubClassList",
                    cache: false,
                    success: function (data) {
                        if (data.success) {
                            _this.subclassLists=data.data;
                        }else
                            _this.common.errorTip(data.errorMessage);
                    }
                });
            },
            //计划备件大类下拉列表
            planCategoryDownValue(){
                var _this=this;
                $.ajax({
                    type: 'GET',
                    url: _this.metadata_service+"planCategory/findPlanCategoryList",
                    cache: false,
                    success: function (data) {
                        if (data.success) {
                            _this.planCategoryLists=data.data;
                        }else
                            _this.common.errorTip(data.errorMessage);
                    }
                });
            },
            cancleUpdate(){
                var _this=this;
                _this.$router.push({path:"/SpareFile"});
            },
            //选中的供货比例的集合
            selectSpare(index,row){    //选中
                var _this=this;
                if(row.matchStatus){
                    _this.selectedSupplyScale.push({"proportion":row.proportion});   //新增供应商弹框中，选中的供应商的信息
                }else{
                    _this.selectedSupplyScale.pop({"proportion":row.proportion});
                }
                /*if($(event.target).parent().attr("class").indexOf("is-checked")!=-1){
                    _this.selectedSupplyScale.push({"proportion":row.proportion});   //新增供应商弹框中，选中的供应商的信息
                }else{
                    _this.selectedSupplyScale.pop({"proportion":row.proportion});
                }*/
            },
            //判断是否有已勾选的供货比例
            judgeSel(){
                var _this=this;
                _this.selectedSupplyScale=[];
                for(var i=0;i<_this.supplierData.length;i++){
                    //console.log(i,_this.supplierData[i].matchStatus)
                    if(_this.supplierData[i].matchStatus){
                        //console.log(i)
                        _this.selectedSupplyScale.push({"proportion":_this.supplierData[i].proportion,});   //新增供应商弹框中，选中的供应商的信息
                    }
                }
            },
            //判断供货比例是否等于100
            judgeSpare(){
                var _this=this;
                var sum=0;
                for(var i=0;i<_this.selectedSupplyScale.length;i++){
                    sum+=Number(_this.selectedSupplyScale[i].proportion);
                }
                //console.log(sum)
                if(sum==100){
                    //console.log("供货比例正确")
                    return true;
                }else{
                    //console.log("供货比例不对")
                    return false;
                }
            },
            //改变比例
            changeProportion(index,row,event){
                var _this=this;
                _this.supplierData[index].proportion=row.proportion;
                _this.judgeSel();
            },
            bianhua(){
                for (let i=0;i<this.originalManufacturerNameList.length;i++){
                    if(this.originalManufacturerName == this.originalManufacturerNameList[i].partnerName){
                    this.originalManufacturerid = this.originalManufacturerNameList[i].id
                    }
                }

            },
            // 点击启用  序列化默认选 “是”
            serializabledefalut(){
                if(this.spareMessage.enabled){
                this.spareMessage.serializable = this.spareMessageDropDown.serializableList[0].value
                }else {
                this.spareMessage.serializable = this.spareMessageDropDown.serializableList[1].value
                }
            },
            //原厂商下拉列表的值  自动完成
            originalManufacturerValue(){
                var _this=this;
                $.ajax({
                    type: 'GET',
                    url: _this.metadata_service+"material/findProviderListByName?name="+_this.originalManufacturerName,
                    cache: false,
                    success: function (data) {
                        if (data.success) {
                            _this.originalManufacturerNameList=data.data;
                        }else
                            // console.log(data.errorMessage);
                            _this.common.errorTip(data.errorMessage);
                    }
                });
            },
            //备件信息下拉列表的值
            dropDownValue(){
                var _this=this;
                var tmp=["meterial.rohsProperty","meterial.psiFlag","meterial.unit","meterial.purchaseMethod","meterial.canSupply","meterial.purchasePriority","meterial.specialTransportRequired","meterial.status","meterial.canAutoAllot","meterial.thinkSellable","meterial.lenovoSellable","meterial.borrowable","meterial.serializable","meterial.property","meterial.originalProduceArea"];
                $.ajax({
                    type:'POST',
                    url:_this.metadata_service+'metadata/getPullDownList',
                    cache:false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType:"application/json;charset=utf-8",
                    success:function(data){
                        if(data.success){
                            _this.spareMessageDropDown=data.data;
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
            },
            // 选择采购方式
            selectPurchaseMethod(){
                var _this=this;
                _this.myPurchaseMethod=_this.spareMessage.purchaseMethod;
                //根据采购方式不同，控制不同的宽度
                if(_this.myPurchaseMethod==2){
                    //供货比例
                    _this.myPurchaseWidth=370;
                    _this.defaultSupplier="";
                }else if(_this.myPurchaseMethod==1){
                    //单独供货
                    _this.myPurchaseWidth=470;
                }
                _this.showSupplierList();
            },
            // 保存
            saveMSG(){
                var _this=this;

                //前端校验
                this.$refs['spareMessage'].validate((valid) => {
                    if (valid) {
                        var tmp={"id": _this.spareMessage.id,"planCategory": _this.spareMessage.planCategory,"enabled": _this.spareMessage.enabled,"serviceCard": _this.spareMessage.serviceCard,"code": _this.spareMessage.code,"name": _this.spareMessage.name,"property": _this.spareMessage.property,"serializable": _this.spareMessage.serializable,"borrowable": _this.spareMessage.borrowable,"lenovoSellable": _this.spareMessage.lenovoSellable,"thinkSellable": _this.spareMessage.thinkSellable,"canAutoAllot": _this.spareMessage.canAutoAllot,"supportMOQ": _this.spareMessage.supportMOQ,"introduceTime": _this.spareMessage.introduceTime,"status": _this.spareMessage.status,"specialTransportRequired": _this.spareMessage.specialTransportRequired,"purchasePriority": _this.spareMessage.purchasePriority,"canSupply": _this.spareMessage.canSupply,"noSupplyReason": _this.spareMessage.noSupplyReason,"purchaseMethod": _this.spareMessage.purchaseMethod,"serviceFactory": _this.spareMessage.serviceFactory,"providerNo": _this.spareMessage.providerNo,"originalNo": _this.spareMessage.originalNo,"originalManufacturer": _this.originalManufacturerid,"originalProduceArea": _this.spareMessage.originalProduceArea,"suttle": _this.spareMessage.suttle,"rawMaterials": _this.spareMessage.rawMaterials,   "standard": _this.spareMessage.standard,"eOLTime": _this.spareMessage.eOLTime,"volumeProductionMOQ": _this.spareMessage.volumeProductionMOQ,"minimumPackageUnit": _this.spareMessage.minimumPackageUnit,"psiFlag": _this.spareMessage.psiFlag,"rohsProperty": _this.spareMessage.rohsProperty,"unit": _this.spareMessage.unit,"remark": _this.spareMessage.remark,"subclass": _this.spareMessage.subclass,"eoltime": _this.spareMessage.eoltime};
                        // console.log("tmp===============================");
                        // console.log(tmp);
                        _this.saveDisabled=true;
                        $.ajax({
                            // xhrFields: { withCredentials: true },
                            type: 'POST',
                            url: _this.metadata_service+"material/update",
                            cache: false,
                            data:JSON.stringify(tmp),
                            dataType:'JSON',
                            contentType: "application/json;charset=utf-8",     //*****
                            success: function (data) {
                                if (data.success) {
                                    var success=_this.languageType=="zh"?'保存成功':'Save Success';
                                    _this.common.successTip(success);
                                    _this.$router.push("/spareFile");
                                    // console.log(_this.$route.matched.matched[0].path);
                                }else{
                                    _this.common.errorTip(data.errorMessage);
                                }  
                                _this.saveDisabled=false;
                            }
                        });
                    } else {
                        var  err=_this.common.formErrorInfo();
                        _this.common.errorTip(err);
                    }
                });

            },
            prepareData(rawData, attributeNames){
                for (var i = attributeNames.length - 1; i >= 0; i--) {
                    if(rawData[attributeNames[i]] == null){
                    //    console.log("prepareData null attribute:" + attributeNames[i])
                        rawData[attributeNames[i]] = "";
                    }else{
                    //    console.log("prepareData before:" + attributeNames[i] + ":" + (typeof rawData[attributeNames[i]]))
                        rawData[attributeNames[i]] = "" + rawData[attributeNames[i]];
                    //    console.log("prepareData after:" + attributeNames[i] + ":"  + (typeof rawData[attributeNames[i]]))
                    }
                }
            },
            // 刚打开页面 默认显示供应商列表
            showSupplierList(){
                var _this=this;
                $.ajax({
                    type: 'GET',
                    url: _this.metadata_service+"material/findMaterialSuppliersByParams?materialCode="+_this.materialCode+"&supplierType="+_this.supplierType,
                    cache: false,
                    success: function (data) {
                        if (data.success) {
                            //console.log(data);
                            _this.supplierData=data.data;
                            _this.judgeSel();//进入页面判断是否有勾选的供货比例
                            // _this.defaultSupplier//获取该备件的默认供应商
                            for(var i=0;i<_this.supplierData.length;i++){
                                if(_this.supplierData[i].defaultStatus==true){
                                    _this.defaultSupplier=_this.supplierData[i].id;
                                    //console.log("默认供应商的code="+_this.defaultSupplier);
                                }
                            }

                        }else
                            // console.log(data.errorMessage);
                            _this.common.errorTip(data.errorMessage);
                    }
                });
            },
            // 复制到索赔商
            copeClaimMaker(index,row){
                var _this=this;
                var tmp={"materialCode":row.materialCode,"supplierType":2,"providerId":row.supplierId,"partnerName":row.name,"partnerCode":row.code};
                _this.copyCDisabled=true;
                $.ajax({
                    type: 'POST',
                    url: _this.metadata_service+"material/insertMateraialSupplier",
                    cache: false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType: "application/json;charset=utf-8",     //*****
                    success: function (data) {
                        if (data.success) {
                            var success=_this.languageType=="zh"?'成功复制到索赔商':'Successfully copied to the claim maker';
                            _this.common.successTip(success);
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                        _this.copyCDisabled=false;     
                    }
                });
            },
            // 复制到维修商
            copeMaintainer(index,row){
                var _this=this;
                var tmp={"materialCode":row.materialCode,"supplierType":3,"providerId":row.supplierId,"partnerName":row.name,"partnerCode":row.code};
                _this.copyMDisabled=true;
                $.ajax({
                    type: 'POST',
                    url: _this.metadata_service+"material/insertMateraialSupplier",
                    cache: false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType: "application/json;charset=utf-8",     //*****
                    success: function (data) {
                        if (data.success) {
                            var success=_this.languageType=="zh"?'成功复制到维修商':'Successfully copied to the maintainer';
                            _this.common.successTip(success);
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                        _this.copyMDisabled=false;   
                    }
                });
            },
            //启用、禁用
            handleStatus(index,row){
                var _this=this;
                _this.supplierId=row.id;
                row.status=!row.status;
                var tmp=[{"id":_this.supplierId,"defaultStatus":row.defaultStatus,"matchStatus":row.matchStatus,"proportion":row.proportion,"status":row.status}];
                $.ajax({
                    type: 'POST',
                    url: _this.metadata_service+"material/updateMateraialSupplier",
                    cache: false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType: "application/json;charset=utf-8",     //*****
                    success: function (data) {
                        if (data.success) {
                            var success=_this.languageType=="zh"?'操作成功':'Successful operation';
                            _this.common.successTip(success);
                        }else
                            _this.common.errorTip(data.errorMessage);
                    }
                });
            },


            //菜单导航
            handleSelect(key, keyPath) {
                var _this=this;
                // console.log(key, keyPath);
                $(".under-table").hide();
                $("."+key).show();
                if(key=="supplier"){
                    _this.supplierType=1;
                    if(_this.languageType=="zh"){
                        _this.title="选择供应商";
                    }else{
                        _this.title="selectSupplier";
                    }
                }else if(key=="claimMaker"){
                    _this.supplierType=2;
                    if(_this.languageType=="zh"){
                        _this.title="选择索赔商";
                    }else{
                        _this.title="selectClaimMaker";    
                    }
                }else{
                    _this.supplierType=3;
                    if(_this.languageType=="zh"){
                        _this.title="选择维修商";
                    }else{
                        _this.title="selectMaintainer";  
                    }
                }

                $.ajax({
                    type: 'GET',
                    url: _this.metadata_service+"material/findMaterialSuppliersByParams?materialCode="+_this.materialCode+"&supplierType="+_this.supplierType,
                    cache: false,
                    success: function (data) {
                        if (data.success) {
                            // console.log(data);
                            _this.supplierData=data.data;                            
                            if(_this.supplierType==1){
                                // console.log("供应商");
                                for(var i=0;i<_this.supplierData.length;i++){
                                    if(_this.supplierData[i].defaultStatus==true){
                                        _this.defaultSupplier=_this.supplierData[i].id;
                                    }
                                }
                            }else if(_this.supplierType==2){
                                // console.log("索赔商");
                                for(var i=0;i<_this.supplierData.length;i++){
                                    if(_this.supplierData[i].defaultStatus==true){
                                        _this.defaultClaimMaker=_this.supplierData[i].id;
                                    }
                                }
                            }else if(_this.supplierType==3){
                                // console.log("维修商");
                                for(var i=0;i<_this.supplierData.length;i++){
                                    if(_this.supplierData[i].defaultStatus==true){
                                        _this.defaultMaintainer=_this.supplierData[i].id;
                                    }
                                }
                            }
                        }else
                            // console.log(data.errorMessage);
                            _this.common.errorTip(data.errorMessage);
                    }
                });

            },

            //新增供应商弹窗的数据列表
            newSupplier(supplierType){
                var _this=this;
                _this.LeadIngInVisible = true;
                //ajax前后查询按钮禁用
                $(".selectAll").ajaxStart(function(){
                    _this.selectDisabled=true;
                });
                $(".selectAll").ajaxStop(function(){
                    _this.selectDisabled=false;
                });
                _this.pageIndex=1;
                _this.partnerIds=[];
                for(var i=0;i<_this.supplierData.length;i++){
                    _this.partnerIds.push(_this.supplierData[i].supplierId);
                }
                var tmp={partnerIds:_this.partnerIds,partnerName:"",partnerCode:"",pageIndex:_this.pageIndex,pageSize:_this.pageSize};
                $.ajax({
                    type: 'POST',
                    url: _this.metadata_service+"material/searchPartnerPage",
                    cache: false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType: "application/json;charset=utf-8",     //*****
                    success: function (data) {
                        if (data.success) {
                            _this.gridData=data.data.dataList;
                            _this.totalNumber=data.data.totalNumber;    //总条数
                            _this.totalPage=data.totalPage;    //总页数
                            _this.providerList=[];
                            $("#supplierMark .el-table").find(".el-checkbox__input").removeClass("is-checked");
                        }else
                            // console.log(data.errorMessage);
                            _this.common.errorTip(data.errorMessage);

                    }
                });
            },
            //保存供应商（供货比例、比例）
            saveSupplier(supplierType){
               var _this=this;
               var postData = [];
               var defaultStatusValue="";      // 是否有默认值
               var judgeSpare=_this.judgeSpare();
               for(var i=0; i<_this.supplierData.length; i++){

                    if(supplierType==1){
                        if(_this.defaultSupplier==_this.supplierData[i].id){
                             _this.supplierData[i].defaultStatus=true;
                            // console.log("保存供应商"+_this.defaultSupplier);
                        }else{
                            _this.supplierData[i].defaultStatus=false;
                        }
                    }else if(supplierType==2){
                        if(_this.defaultClaimMaker==_this.supplierData[i].id){
                             _this.supplierData[i].defaultStatus=true;
                            // console.log("保存索赔商"+_this.defaultClaimMaker);
                        }else{
                            _this.supplierData[i].defaultStatus=false;
                        }
                    }else if(supplierType==3){
                        if(_this.defaultMaintainer==_this.supplierData[i].id){
                            _this.supplierData[i].defaultStatus=true;
                            // console.log("保存维修商"+_this.defaultMaintainer);
                        }else{
                            _this.supplierData[i].defaultStatus=false;
                        }
                    }
                   postData.push({
                        id: _this.supplierData[i].id,
                        status: _this.supplierData[i].status,
                        defaultStatus:_this.supplierData[i].defaultStatus,
                        matchStatus: _this.supplierData[i].matchStatus,
                        proportion: _this.supplierData[i].proportion
                    });
                    defaultStatusValue+=defaultStatusValue.concat(_this.supplierData[i].defaultStatus);
               }

                if(_this.myPurchaseMethod==1){
                    if(defaultStatusValue.indexOf("true")!=-1) {
                        // 有默认供应商、索赔商、维修商时，才可以保存
                        _this.saveSDisabled=true;
                        $.ajax({
                            type: 'POST',
                            url: _this.metadata_service + "material/updateMateraialSupplier",
                            cache: false,
                            data: JSON.stringify(postData),
                            dataType: 'JSON',
                            contentType: "application/json;charset=utf-8",     //*****
                            success: function (data) {
                                if (data.success) {
                                    var success=_this.languageType=="zh"?'保存成功':'Save Success';
                                    _this.common.successTip(success);
                                } else{
                                    _this.common.errorTip(data.errorMessage);
                                }
                                _this.saveSDisabled=false;  
                            }
                        });
                    }else {
                        _this.common.errorTip("请选择默认"+_this.title);
                    }
                }else{
                    if(judgeSpare){
                        _this.saveSDisabled=true;
                        $.ajax({
                            type: 'POST',
                            url: _this.metadata_service+"material/updateMateraialSupplier",
                            cache: false,
                            data:JSON.stringify(postData),
                            dataType:'JSON',
                            contentType: "application/json;charset=utf-8",     //*****
                            success: function (data) {
                                if (data.success) {
                                    _this.common.successTip("供货比例、比例修改成功");
                                }else{
                                    _this.common.errorTip(data.errorMessage);
                                }
                                _this.saveSDisabled=false;    
                            }
                        });
                    }else{
                        _this.common.errorTip("供货比例不正确");
                    }

                }
            },
            //新增供应商弹窗中的查询
            search(pageIndex,pageSize){
                var _this=this;
                //让所有的不选中

                _this.LeadIngInVisible = true;
                // if(_this.originalManufacturerName==null){
                //     _this.originalManufacturerName="";
                // }
                var tmp={partnerIds:_this.partnerIds,partnerName:_this.selectForm.name,partnerCode:_this.selectForm.code,pageIndex:pageIndex,pageSize:pageSize};
                // _this.originalManufacturerName
                $.ajax({
                    type: 'POST',
                    url: _this.metadata_service+"material/searchPartnerPage",
                    cache: false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType: "application/json;charset=utf-8",     //*****
                    success: function (data) {
                        if (data.success) {
                            _this.gridData=data.data.dataList;
                            _this.totalNumber=data.data.totalNumber;    //总条数
                            _this.totalPage=data.totalPage;    //总页数      
                        }else
                            // console.log(data.errorMessage);
                            _this.common.errorTip(data.errorMessage);

                    }
                });
            },
            // 新增供应商查询出来的列表   分页
            //   分页
            handleSizeChange(val) {          //每页条数
                var _this=this;
                _this.pageSize=val;
                _this.search(_this.pageIndex,_this.pageSize);
            },
            handleCurrentChange(val) {       // 当前页
                var _this=this;
                _this.pageIndex=val;
                _this.search(_this.pageIndex,_this.pageSize);
            },
            //新增弹窗中的确定按钮   选择供应商
            /*selectMateraialSupplier(index,row,event){    //选中
                var _this=this;
                if($(event.target).parent().attr("class").indexOf("is-checked")!=-1){
                    _this.providerList.push({"id":row.id,"partnerName":row.partnerName,"partnerCode":row.partnerCode});   //新增供应商弹框中，选中的供应商的信息
                }else{
                    _this.providerList.pop({"id":row.id,"partnerName":row.partnerName,"partnerCode":row.partnerCode});
                }
            },*/
            // selection-change	当选择项发生变化时会触发该事件
            handleSelectionChange(val){
                var _this=this;
                _this.providerList=val;
            },
            //处理参数，删去多余的需要保存和提交的参数
            dealParms(){
                var _this=this;
                var parms=_this.providerList;
                var newParms=[];
                for(var i=0;i<parms.length;i++){
                    var parmsObj={};
                    parmsObj.id=parms[i].id;
                    parmsObj.partnerName=parms[i].partnerName;
                    parmsObj.partnerCode=parms[i].partnerCode;
                    newParms.push(parmsObj);
                }
                return newParms
            },
            insertMateraialSupplier(){   //确定新增
                var _this=this;
                var materList=_this.dealParms();
                var tmp={"materialCode":_this.materialCode,"supplierType":_this.supplierType,"providerList":materList};
                $.ajax({
                    type: 'POST',
                    url: _this.metadata_service+"material/insertMateraialSupplierList",
                    cache: false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType: "application/json;charset=utf-8",     //*****
                    success: function (data) {
                        console.log(data);
                        if (data.success) {
                            // console.log(data);
                            // console.log("供应商新增成功");
                            //供应商列表 实时更新
                            $.ajax({
                                type: 'GET',
                                url: _this.metadata_service+"material/findMaterialSuppliersByParams?materialCode="+_this.materialCode+"&supplierType="+_this.supplierType,
                                cache: false,
                                success: function (data) {
                                    if (data.success) {
                                        // console.log(data);
                                        _this.supplierData=data.data;
                                        _this.LeadIngInVisible = false;
                                    }else
                                        // console.log(data.errorMessage);
                                        _this.common.errorTip(data.errorMessage);
                                }
                            });
                        }else
                            // console.log(data.errorMessage);
                            _this.common.errorTip(data.errorMessage);
                    }
                });

            }
        }
    }
</script>
